// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import App from './App'
import router from './router'

// 引入Echarts
import  * as echarts from 'echarts'
Vue.prototype.$echarts = echarts



Vue.config.productionTip = false


//引入模块
 
var axios=require("axios")
//设置baseURL


axios.defaults.baseURL="http://172.16.13.130/peace/"
axios.interceptors.request.use(config => {
    config.headers['token'] = sessionStorage.getItem("user_code");
    return config
  }, err => {
  })





//全局注册
Vue.prototype.$axios=axios

//使用elementUI 
Vue.use(ElementUI);


new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>',
  created() {
    router.beforeEach((to, from, next) => {

      if (to.meta.requireAuth) {  // 如果访问的页面必须要登录

        if (sessionStorage.getItem("user_name") == null) { //检查当前如果已经登陆过

          next({
            path: '/', //path到登录页面
           // query: { redirect: to.fullPath }
          })
        } else { //否则先登录
          next(); //如果已经登录，则继续执行
        }
      } else { //不需要登录则不执行其他操作
        next();
      }
    })
  }
})
